<template>
    <div id="teamPage">
        <van-search v-model="searchText" placeholder="搜索队伍" @search="onSearch" />
        <team-card-list :teamList="teamList" />
        <van-empty v-if="teamList?.length < 1" description="还没加入队伍"/>
    </div>
</template>

<script setup>
import TeamCardList from "../components/TeamCardList.vue";
import {useRouter} from "vue-router";
import {onMounted, ref} from "vue";
import myAxios from "../plugins/myAxios";
import {showFailToast, showToast} from "vant";

const router = useRouter();
const searchText = ref('');

const teamList = ref([]);

/**
 * 搜索队伍
 * @param val
 * @returns {Promise<void>}
 */
const listTeam = async (val = '') => {
    const res = await myAxios.get("/team/list/my/join", {
        params: {
            searchText: val,
            pageNum: 1,
        },
    })
    if (res?.code === 0) {
        teamList.value = res.data;
    } else if(res?.code === 40001){
        showFailToast('近期暂无队伍创建，快来创建队伍吧');
    }else if(res?.code === 40100){
        showFailToast('请登录后重试！');
    }else {
        showFailToast('加载队伍失败，请刷新重试');
    }
}


// 页面加载时只触发一次
onMounted( () => {
    listTeam();
})

const onSearch = (val) => {
    listTeam(val);
};

</script>

<style scoped>

</style>